package cn.edu.njust.alg.leetcode;

public class Leetcode_191_Number_of_1_Bits {

	public static int hammingWeight(int n) {
		int count = 0;
		int k = n;
		while (k != 0) {
			count++;
			k = k & (k - 1);
		}

		return count;
	}

	public static int reverseBits(int n) {
		int res = 0;
		for (int i = 0; i < 32; ++i) {
			res |= (((n >> i) & 1) << (31 - i));
		}
		return res;
	}

	public static void main(String[] args) {
		int i = 1341;

		System.out.println(Integer.toBinaryString(i) + " : "
				+ Integer.toBinaryString(reverseBits(i)));
	}

}
